{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "charged-holly",
   "metadata": {},
   "outputs": [],
   "source": [
    "#https://www.geeksforgeeks.org/reflection-in-python/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "fatal-constitution",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Python program to illustrate reflection  \n",
    "def reverse(sequence):  \n",
    "    sequence_type = type(sequence)  \n",
    "    empty_sequence = sequence_type()  \n",
    "      \n",
    "    if sequence == empty_sequence:  \n",
    "        return empty_sequence  \n",
    "      \n",
    "    rest = reverse(sequence[1:])  \n",
    "    first_sequence = sequence[0:1]  \n",
    "      \n",
    "    # Combine the result  \n",
    "    final_result = rest + first_sequence \n",
    "      \n",
    "    return final_result  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "nervous-myanmar",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[40, 30, 20, 10]\n",
      "skeeGroFskeeG\n"
     ]
    }
   ],
   "source": [
    "  \n",
    "# Driver code  \n",
    "print(reverse([10, 20, 30, 40]))  \n",
    "print(reverse(\"GeeksForGeeks\"))  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "blond-norfolk",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\nReflection is an API which is used to examine or modify the behavior of methods, classes, interfaces at runtime.\\n\\nThe required classes for reflection are provided under java.lang.reflect package.\\nReflection gives us information about the class to which an object belongs and also the methods of that class which can be executed by using the object.\\nThrough reflection we can invoke methods at runtime irrespective of the access specifier used with them.\\n'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "Reflection is an API which is used to examine or modify the behavior of methods, classes, interfaces at runtime.\n",
    "\n",
    "The required classes for reflection are provided under java.lang.reflect package.\n",
    "Reflection gives us information about the class to which an object belongs and also the methods of that class which can be executed by using the object.\n",
    "Through reflection we can invoke methods at runtime irrespective of the access specifier used with them.\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "meaningful-jurisdiction",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x is not callable\n",
      "y is callable\n"
     ]
    }
   ],
   "source": [
    "x = 5\n",
    "\n",
    "def testFunction():\n",
    "  print(\"Test\")\n",
    "   \n",
    "y = testFunction\n",
    "\n",
    "if (callable(x)):\n",
    "    print(\"x is callable\")\n",
    "else:\n",
    "    print(\"x is not callable\")\n",
    "\n",
    "if (callable(y)):\n",
    "    print(\"y is callable\")\n",
    "else:\n",
    "    print(\"y is not callable\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "martial-halifax",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "class Foo1:\n",
    "  def __call__(self):\n",
    "    print('Print Something')\n",
    "\n",
    "print(callable(Foo1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "prompt-ceramic",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']\n",
      "['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']\n"
     ]
    }
   ],
   "source": [
    "number = [1,2,3]\n",
    "print(dir(number))\n",
    "\n",
    "characters = [\"a\", \"b\"]\n",
    "print(dir(characters))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "capable-nurse",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The salary is: 25000\n",
      "The salary is: 25000\n"
     ]
    }
   ],
   "source": [
    "class Employee:\n",
    "    salary = 25000\n",
    "    company_name= \"geeksforgeeks\"\n",
    "\n",
    "employee = Employee()\n",
    "print('The salary is:', getattr(employee, \"salary\"))\n",
    "print('The salary is:', employee.salary)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "electronic-poker",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'function' object has no attribute 'PyEval_GetBuiltins'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-10-bdccc01cb386>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mreverse\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mPyEval_GetBuiltins\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m: 'function' object has no attribute 'PyEval_GetBuiltins'"
     ]
    }
   ],
   "source": [
    "reverse.PyEval_GetBuiltins()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "strong-wound",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
